home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8490 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Combine zero-offset with unit-offset arrays ?
  5. Date: 4 Mar 1996 10:00:31 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4hfb3vINNmlg@keats.ugrad.cs.ubc.ca>
  8. References: <4hes0h$52qi@info4.rus.uni-stuttgart.de> <4hfau5INNme5@keats.ugrad.cs.ubc.ca>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4hfau5INNme5@keats.ugrad.cs.ubc.ca>,
  12. Kazimir Kylheku <c2a192@ugrad.cs.ubc.ca> wrote:
  13. >#define fa(x) (fa[x-1])
  14. >{
  15. >    int foo = fa(1);
  16. >}
  17.  
  18. By the way, that should be
  19.  
  20. #define fa(x) (fa[(x)-1])
  21.  
  22. since there are many expressions with lower precedence than -, but higher than
  23. comma, such as shift and and bitwise logic operators.
  24.  
  25. >which now gives you fa[1-1], which is *((fa) + 1 - 1). This is defined. The
  26. >standard allows you generate a pointer which references one element past the
  27. >end of the array, thus if you put in the subscript 10,  you would have
  28. >*((fa) + 10 - 1). ANSI condones the generation of a pointer to the non-existant
  29. >element of the array that is conceptually one index past the last one, in
  30. >order to support certain common coding idioms.
  31. >-- 
  32. >
  33.  
  34.  
  35. -- 
  36.  
  37.